<template>
  <view>
    <web-view :src="url" :update-title="false"></web-view>
    <view class="tools">

    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        site: {
          name: '未知'
        },
        url: '',
        curPath: [],
        loading: false,
      }
    },
    created() {
      this.fetchData()
      this.site.name = this.defcku.name
    },
    onNavigationBarButtonTap(e) {
      if (e.index == 1) {
        this.backPage()
        return
      }
      this.handleShowAction()
    },
    methods: {
      fetchData() {
        this.list = this.defcku.drive
        if (this.list.length > 0) {
          this.handleChange(0)
        }
        // console.log(this.list)
      },
      backPage() {
        uni.switchTab({
          url: '/pages/me/me'
        })
        // uni.navigateBack({delta:1})
        // console.log('backPage')
      },
      handleChange(index) {
        this.site = this.list[index]
        uni.setNavigationBarTitle({
          title: `云盘 (${this.site.name})`
        })
        let url = `${this.site.server}${this.site.startPage}`
        if (this.site.startPage) {
          this.curPath.push(this.site.startPage.replace(/\//g, ''))
        }
        // #ifdef H5
        // window.open(url)
        // #endif

        this.url = url
        console.log(this.curPath)
        // this.fetchFiles() 
      },
      fetchFiles() {
        let path = this.curPath.join('/')
        let url = `${this.site.server}/${path}/`
        this.$u.get(url).then(response => {
          console.log(url)
        }).catch(err => {
          console.log(err)
        })
      },
      handleShowAction() {
        let list = this.list.map(t => t.name)
        uni.showActionSheet({
          itemList: list,
          success: (res) => {
            this.handleChange(res.tapIndex)
          }
        })
      }
    }
  }
</script>

<style>
  .tools {
    position: fixed;
    display: none;
    bottom: 10px;
    z-index: 999;
    width: 400upx;
    height: 500upx;
    border: 1px solid #096;
  }
</style>